package com.ocl.www.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ocl.www.basic.BasicController;
import com.ocl.www.domain.Category;
import com.ocl.www.domain.User;
import com.ocl.www.service.CategoryService;

@RestController
@RequestMapping("/category")
public class CategoryController extends BasicController{
	
	
	@Autowired
	private CategoryService categoryService;
	private Logger log = Logger.getLogger(CategoryController.class);
	
	@RequestMapping(value = "/getCategorys", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public List<Category> getCategorys () {
		log.info("again");
		Category haboy = new Category();
		List<String> list = new ArrayList<String>();
		List<Category> reslist = null;
		try {
//			User loginUser = new User();
//			loginUser.setUserName(SecurityUtils.getSubject().getPrincipal().toString());
//			user = userService.findUserInfo(loginUser);

			log.info("正在查询数据库的数据。。。。");
			reslist = categoryService.selectCategoryInfo();
			
//			for(int i =0;i<reslist.size();i++){
//				
//				list.add(((Category)reslist.get(i)).getCategoryName());
//				//System.out.println(" i === "+i);
//			}
			//System.out.println("查询数据库");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return reslist;
	}
}
